package entity

import (
	"time"
	"xr-game-server/core/constants/db"
	"xr-game-server/core/migrate"
	"xr-game-server/core/syndb"
)

const (
	TbPlayerTaskResetTime = "player_task_reset_times"
)

const (
	PlayerTaskResetTimeDayTime  db.TbCol = "day_time"
	PlayerTaskResetTimeWeekTime db.TbCol = "week_time"
)

type PlayerTaskResetTime struct {
	migrate.OneModel
	DayTime  *time.Time `gorm:"comment:重置时间-天"`
	WeekTime *time.Time `gorm:"comment:重置时间-周"`
}

func initTaskResetTime() {
	syndb.RegLazyWithSmall(TbPlayerTaskResetTime, db.CreatedAtName)
	syndb.RegLazyWithSmall(TbPlayerTaskResetTime, db.UpdatedAtName)

	syndb.RegLazyWithSmall(TbPlayerTaskResetTime, PlayerTaskResetTimeDayTime)
	syndb.RegLazyWithSmall(TbPlayerTaskResetTime, PlayerTaskResetTimeWeekTime)
	migrate.AutoMigrate(&PlayerTaskResetTime{})
}

func NewPlayerTaskResetTime(roleId uint64) *PlayerTaskResetTime {
	ret := &PlayerTaskResetTime{}
	ret.ID = roleId
	ret.SetCreatedAt(time.Now())
	ret.SetUpdatedAt(time.Now())
	return ret
}

func (receiver *PlayerTaskResetTime) SetDayTime(val *time.Time) {
	receiver.DayTime = val
	receiver.SetUpdatedAt(time.Now())
	syndb.AddDataToLazyChan(TbPlayerTaskResetTime, PlayerTaskResetTimeDayTime, &syndb.ColData{
		IdVal:  receiver.ID,
		ColVal: val,
	})
}
func (receiver *PlayerTaskResetTime) SetWeekTime(val *time.Time) {
	receiver.WeekTime = val
	receiver.SetUpdatedAt(time.Now())
	syndb.AddDataToLazyChan(TbPlayerTaskResetTime, PlayerTaskResetTimeWeekTime, &syndb.ColData{
		IdVal:  receiver.ID,
		ColVal: val,
	})
}
func (receiver *PlayerTaskResetTime) SetCreatedAt(val time.Time) {
	receiver.CreatedAt = val
	syndb.AddDataToLazyChan(TbPlayerTaskResetTime, db.CreatedAtName, &syndb.ColData{
		IdVal:  receiver.ID,
		ColVal: val,
	})
}
func (receiver *PlayerTaskResetTime) SetUpdatedAt(val time.Time) {
	receiver.UpdatedAt = val
	syndb.AddDataToLazyChan(TbPlayerTaskResetTime, db.UpdatedAtName, &syndb.ColData{
		IdVal:  receiver.ID,
		ColVal: val,
	})
}
